package com.haide.channel.pro.service.impl;

import com.haide.channel.pro.constant.ConfigDict;
import com.haide.channel.pro.pojo.Result;
import com.haide.channel.pro.pojo.dto.BindCardReqDto;
import com.haide.channel.pro.pojo.dto.BindCardRespDto;
import com.haide.channel.pro.service.BindCardService;
import com.haide.channel.pro.util.ExceptionUtils;
import com.haide.channel.pro.util.HttpUtil;
import com.haide.channel.pro.util.RequestUtil;
import com.haide.channel.pro.util.verifyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 绑卡业务实现类
 * <p>
 * 1.
 * </p>
 *
 * @author : wukong
 * @version : 1.0.0
 * @date : 2018/7/18
 */
@Slf4j
@Service
public class BindCardServiceImpl implements BindCardService {
    @Autowired
    private HttpUtil httpUtil;

    @Override
    public Result<BindCardRespDto> bindCard(BindCardReqDto bindCardReqDto) {
        log.info("绑卡，请求:{}", bindCardReqDto);
        Result<BindCardRespDto> result;
        try {
            String resultStr = httpUtil.get(RequestUtil.getUrl(bindCardReqDto, ConfigDict.BIND_CARD_URL));
            BindCardRespDto bindCardRespDto = verifyUtil.getSuccessResult(resultStr, BindCardRespDto.class);
            result = new Result<>(bindCardRespDto);
        } catch (Exception e) {
            log.error("绑卡-异常", e);
            result = ExceptionUtils.getResponse(e);
        }
        log.info("绑卡，响应:{}", result);
        return result;
    }
}
